package com.kgc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.mapper.NewscommentMapper;
import com.kgc.pojo.Newscomment;
import com.kgc.pojo.NewscommentExample;
import com.kgc.pojo.NewsdetailExample;
import com.kgc.service.NewscommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class NewscommentServiceImpl implements NewscommentService {
    @Autowired
    private NewscommentMapper newscommentMapper;


    public List<Newscomment> selectNewscommentAll() {
        return newscommentMapper.selectByExample(null);
    }

    public Newscomment selectById(Integer id) {
        NewscommentExample newscommentExample=new NewscommentExample();
        NewscommentExample.Criteria criteria=newscommentExample.createCriteria();
        if(null==id||id.equals(0)){
            return null;
        }
        Newscomment newscomment=newscommentMapper.selectByPrimaryKey(id);
        return newscomment;
    }

    //分页查询
    public PageInfo<Newscomment> selectNewscommentByCondition(Integer newsid, Integer pageNo, Integer pageSize) {
        NewscommentExample newscommentExample=new NewscommentExample();
        NewscommentExample.Criteria criteria=newscommentExample.createCriteria();
        if(newsid!=null&&newsid!=0){
            criteria.andNewsidEqualTo(newsid);
        }
        PageHelper.startPage(pageNo,pageSize);
        List<Newscomment> newscomments=newscommentMapper.selectByExample(newscommentExample);
        if(null==newscomments||newscomments.size()==0){
            return null;
        }
        PageInfo<Newscomment> pageInfo=new PageInfo<Newscomment>(newscomments);
        return pageInfo;
    }



    public boolean addNewscomment(Newscomment newscomment) {
        return newscommentMapper.insertSelective(newscomment)>0?true:false;
    }
}
